<?php
namespace app\admin\controller;

use app\admin\logic\MachineLogic;
use app\common\respond\HttpApi;

/**
 * 上位机类
 */
class MachineController
{
    /**
     * @Description 列表
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/04/01 10:48:07
     * @return \think\response\Json
     */
    public function list(HttpApi $respond)
    {
        $param = [
            'page' => (int)request()->get('page')?: 1,
            'page_size' => (int)request()->get('page_size')?: 10,
            'machine_code' => request()->get('machine_code'),
            'status' => request()->get('status'),
        ];
        $rule = [
            'page' => 'require|integer|>:0',
            'page_size' => 'require|integer|>:0',
            'machine_code' => 'max:16',
            'status' => 'integer|in:10,20'
        ];
        validate($rule)->check($param);

        $logic = new MachineLogic();
        $data = $logic->getList($param);

        return $respond->success($data);
    }

    /**
     * 下拉列表
     *
     * @param HttpApi $respond
     * @return \think\response\Json
     */
    public function getPull(HttpApi $respond)
    {
        $param = [
            'page' => (int)request()->get('page')?: 1,
            'page_size' => (int)request()->get('page_size')?: 10,
            'machine_code' => request()->get('machine_code'),
        ];
        $rule = [
            'page' => '>:0',
            'page_size' => '>:0',
        ];
        validate($rule)->check($param);

        $logic = new MachineLogic();
        $data = $logic->getPull($param);

        return $respond->success($data);
    }

}
